// pages/mine/mine.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "",
    birthday: "",
    gender: null,
    phone: "",
    childrenName: "",
    identity: "",
    relatedParents: [],
    studentNumber: "",
    headImg: "/static/images/headImg.png",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;
    let parentInfo = wx.getStorageSync("parent");
    let parents = wx.getStorageSync("parents");
    let studentInfo = wx.getStorageSync("student");
    this.setData({
      headImg: app.globalData.userInfo.avatarUrl,
      name: parentInfo.name,
      birthday: new Date(parentInfo.birthday).format("yyyy-MM-dd"),
      gender: parentInfo.gender,
      phone: parentInfo.phone,
      childrenName: studentInfo.name,
      identity: parentInfo.relationName,
      studentNumber: studentInfo.studentNumber,
      relatedParents: this.unique(parents).join("、"),
    })
  },
  //数组去重
  unique(list) {
    let map = new Map();
    list.forEach(item => {
      map.set(item, item);
    })

    return [...map.keys()];
  },
  //跳转我的信息
  toBasicInfoPage() {
    wx.setStorageSync("basicInfo", {
      name: this.data.name,
      birthday: this.data.birthday,
      identity: this.data.identity,
    })
    wx.navigateTo({
      url: "/pages/mine/basicInfo/basicInfo"
    })
  },
  //跳转我的小孩
  toMyChild() {
    wx.navigateTo({
      url: "/pages/mine/myChild/myChild?studentNumber=" + this.data.studentNumber
    })
  }

})